<?php
header("Content-type: text/html; charset=utf-8");
ini_set('display_errors', 1);
set_time_limit(0);
include_once dirname(dirname(__FILE__)) . '/mgtv_v2/mgtv_init.php';

$sql = "select nns_id,nns_task_id,nns_task_name from nns_mgtvbk_c2_log where nns_org_id='sihua' and nns_task_type='Movie' and nns_action='REGIST'   and nns_result='[0]' and nns_notify_result is null  limit 12000";
$db = nn_get_db(NL_DB_WRITE);
$infos = nl_db_get_all($sql, $db);
foreach ($infos as $info) {
	
	
	
	if(empty($info['nns_task_id'])){
		$sql_up1 = "update nns_mgtvbk_c2_log set nns_again=1 ,nns_notify_result='-1',nns_modify_time=now() where nns_id='".$info['nns_id']."'";
		nl_execute_by_db($sql_up1,$db);
		continue;
	}
	
	$sql = "select * from nns_mgtvbk_c2_task where nns_org_id='sihua' and nns_type='media' and nns_ref_id='{$info['nns_task_id']}'";
	$c2info = nl_db_get_one($sql, $db);
	
	if(empty($c2info)||$c2info==null){
		$sql_up1 = "update nns_mgtvbk_c2_log set nns_again=1 ,nns_notify_result='-1',nns_modify_time=now() where nns_id='".$info['nns_id']."'";
		nl_execute_by_db($sql_up1,$db);
		continue;
	}
	
	if($c2info['nns_status']==0||$c2info['nns_status']==6){			
		continue;
	}
	
	echo $info['nns_task_name'].PHP_EOL;
	
	$sql_up1 = "update nns_mgtvbk_c2_log set nns_again=1 ,nns_notify_result='-1',nns_modify_time=now() where nns_id='".$info['nns_id']."'";
	nl_execute_by_db($sql_up1,$db);
	
	$sql_up2 = "update nns_mgtvbk_c2_task set nns_status=1,nns_epg_status=97 where nns_id='".$c2info['nns_id']."'";
	
	nl_execute_by_db($sql_up2,$db);
}